﻿using UnityEngine;
using UnityEditor;


[CustomEditor(typeof(TSprite))]
public class TSpriteInspector : Editor{

	protected TSprite sprite;
	
	protected virtual void OnEnable ()
	{
		sprite = target as TSprite;
	}
	
	public override void OnInspectorGUI ()
	{
		base.OnInspectorGUI ();
		
		GUILayout.BeginVertical();
		
		int hp = EditorGUILayout.IntField("HP", sprite.Hp);
		if(hp != sprite.Hp) {sprite.Hp = hp;}
		
		int mp = EditorGUILayout.IntField("MP", sprite.Mp);
		if(mp != sprite.Mp) {sprite.Mp = mp;}
		
		int attack = EditorGUILayout.IntField("Attack", sprite.AttackValue);
		if(attack != sprite.AttackValue) {sprite.AttackValue = attack;}
		
		int defense = EditorGUILayout.IntField("Defense", sprite.DefenseValue);
		if(defense != sprite.DefenseValue) {sprite.DefenseValue = defense;}
		
		float attackFrequency = EditorGUILayout.FloatField("AttackFrequency", sprite.AttackFrequency);
		if(attackFrequency != sprite.AttackFrequency) {sprite.AttackFrequency = attackFrequency;}
		
		float attackDistance = EditorGUILayout.FloatField("AttackDistance", sprite.AttackDistance);
		if(attackDistance != sprite.AttackDistance) {sprite.AttackDistance = attackDistance;}
		
		int bulletId = EditorGUILayout.IntField("BulletId", sprite.BulletId);
		if(bulletId != sprite.BulletId) {sprite.BulletId = bulletId;}
		
		if(sprite.MoveType != MoveTypsEnum.Idle)
		{
			float speedY = EditorGUILayout.FloatField("SpeedY", sprite.SpeedY);
			if(speedY != sprite.SpeedY) {sprite.SpeedY = speedY;}
		}
		
		if(sprite.MoveType == MoveTypsEnum.Y_Axis_Line_X_Axis_PingPong ||
			sprite.MoveType == MoveTypsEnum.Y_Axis_Stop_X_Axis_PingPong)
		{
			float speedX = EditorGUILayout.FloatField("SpeedX", sprite.SpeedX);
			if(speedX != sprite.SpeedX) {sprite.SpeedX = speedX;}
			
			int xPingPongLength = EditorGUILayout.IntField("XPingPongLength", sprite.XPingPongLength);
			if(xPingPongLength != sprite.XPingPongLength) {sprite.XPingPongLength = xPingPongLength;}
		}
		
		if(sprite.MoveType == MoveTypsEnum.Y_Axis_Stop_Pos ||
			sprite.MoveType == MoveTypsEnum.Y_Axis_Stop_X_Axis_PingPong)
		{
			int yStopPos = EditorGUILayout.IntField("YStopPos", sprite.YStopPos);
			if(yStopPos != sprite.YStopPos) {sprite.YStopPos = yStopPos;}
		}
		
		MoveTypsEnum moveType = (MoveTypsEnum)EditorGUILayout.EnumPopup("MoveType", sprite.MoveType);
		if(moveType != sprite.MoveType) {sprite.MoveType = moveType;}
		
		AttackTypeEnum attackType = (AttackTypeEnum)EditorGUILayout.EnumPopup("AttackType", sprite.AttackType);
		if(attackType != sprite.AttackType) {sprite.AttackType = attackType;}
		
		GUILayout.EndVertical();
	}
}
